<?php
  require_once('tpl/header.php');
?>
<form action="">
	<input type="text" name="key">
	<input type="submit" name="搜索">
</form>

   <?php 
 require_once("../system/loginCheck.php");
	      require_once("../system/dbConn.php");
	      connect();
	      $sql="select * from videos join videotype on videos.tid=videotype.tid";//多表联查
	      if (isset($_GET["key"])) {
	      	$key=$_GET["key"];
	      	$sql=$sql." where videoname like '%{$key}%'";
	      }
	      $result=mysql_query($sql);//结果集

       

          if(!isset($_GET["page"])){
        $page=1;
    }else{
        $page=$_GET["page"];
    }
    $totalrows=mysql_num_rows($result);//记录总数
    $rowsperpage=6;//每页显示多少条记录
    if($totalrows%$rowsperpage==0){
        $totalpages=$totalrows/$rowsperpage;
    }else{
        $totalpages=ceil($totalrows/$rowsperpage);//向下取整
        }//分几页
    $start=($page-1)*$rowsperpage;//从第几页开始。
    $sql0=$sql." limit $start,$rowsperpage";//重写sql语句
    // echo "$sql0";
    $result0=mysql_query($sql0);//改变每次执行的初始值。


    ?>

    <table class="table table-hover">
    	<tr>
    		<td>序号</td>
    		<td>视频名称</td>
    		<td>视频类型</td>
    		<td>海报图片</td>
    		<td>上传时间</td>
    		<td>操作</td>
    	</tr>
          <?php 
          $i=1;
          while ($row=mysql_fetch_assoc($result0)) {
          	          
           ?> 
           <tr>
    		<td><?php echo $i++ ?></td>
    		<td><?php echo $row["videoname"] ?></td>
    		<td><?php echo $row["typename"] ?></td>
    		<td><img src="../posters/<?php echo $row["pic"] ?>"width="80" height="80" title="<?php echo $row["intro"]; ?>" ></td>
        <!-- intro 点击图片出现视频简介 -->
    		<td><?php echo $row["uploaddate"] ?></td>
    		<td><a href="videoEdit.php?vid=<?php echo $row["vid"] ?>">修改</a> | <a href="doVideoDelete.php?vid=<?php echo $row["vid"]; ?>">删除</a></td>
    	</tr>
           <?php 
           }
            ?>
            </table>
            <h3 align="center">
            <?php 
            echo "共有".$totalrows."条记录，共分了".$totalpages."页"."&nbsp;";
            // 首页，上一页的实现
            if ($page==1) {
            echo "首页"."&nbsp";
            }else{
            echo "<a href=?page=1>首页</a>"."&nbsp";
            }
            if ($page==1) {
            echo "上一页"."&nbsp";
            }else{
            echo "<a href=?page=".($page-1).">上一页</a>"."&nbsp";
            }
            //第i页的超链接
            for ($i=1; $i<=$totalpages ; $i++) { 
                echo "<a href=?page=$i>第{$i}页</a>"."&nbsp";
            }
            // 尾页下一页的实现

            if ($page==$totalpages) {
            echo "下一页"."&nbsp";
            }else{
            echo "<a href=?page=".($page+1).">下一页</a>"."&nbsp";
            }
            if ($page==$totalpages) {
            echo "尾页"."&nbsp";
            }else{
            echo "<a href=?page=$totalpages>尾页</a>"."&nbsp";
            }
             ?>
        </h3>


<?php
  require_once('tpl/footer.php');
?>